Histopathology Research Template 🔬


1 Introduction

  • State the marker of interest, the study objectives, and hypotheses (Knijn, Simmer, and Nagtegaal 2015).1

2 Materials & Methods

Describe Materials and Methods as highlighted in (Knijn, Simmer, and Nagtegaal 2015).2

  • Describe patient characteristics, and inclusion and exclusion criteria

  • Describe treatment details

  • Describe the type of material used

  • Specify how expression of the biomarker was assessed

  • Describe the number of independent (blinded) scorers and how they scored

  • State the method of case selection, study design, origin of the cases, and time frame

  • Describe the end of the follow-up period and median follow-up time

  • Define all clinical endpoints examined

  • Specify all applied statistical methods

  • Describe how interactions with other clinical/pathological factors were analyzed


2.1 Header Codes

Codes for general settings.3

Setup global chunk settings4

knitr::opts_chunk$set(
    eval = TRUE,
    echo = TRUE,
    fig.path = here::here("figs/"),
    message = FALSE,
    warning = FALSE,
    error = FALSE,
    cache = FALSE,
    comment = NA,
    tidy = TRUE,
    fig.width = 6,
    fig.height = 4
)

Load Library

see R/loadLibrary.R for the libraries loaded.

source(file = here::here("R", "loadLibrary.R"))

2.2 Generate Fake Data

Codes for generating fake data.5

Generate Fake Data

This code generates a fake histopathological data. Some sources for fake data generation here6 , here7 , here8 , here9 , here10 , here11 , here12 , here13 , and here14 .

Use this code to generate fake clinicopathologic data

source(file = here::here("R", "gc_fake_data.R"))
wakefield::table_heat(x = fakedata, palette = "Set1", flip = TRUE, print = TRUE)


2.3 Import Data

Codes for importing data.15

Read the data

library(readxl)
mydata <- readxl::read_excel(here::here("data", "mydata.xlsx"))
# View(mydata) # Use to view data after importing

Add code for import multiple data purrr reduce


2.4 Study Population

2.4.1 Report General Features

Codes for reporting general features.16

Dataframe Report

# Dataframe report
mydata %>% select(-contains("Date")) %>% report::report(.)
The data contains 250 observations of the following variables:
  - ID: 250 entries: 001, n = 1; 002, n = 1; 003, n = 1 and 247 others
  - Name: 249 entries: Adayah, n = 1; Adeja, n = 1; Adelaina, n = 1 and 246 others (1 missing)
  - Sex: 2 entries: Male, n = 135; Female, n = 114 (1 missing)
  - Age: Mean = 49.05, SD = 13.68, range = [25, 73], 1 missing
  - Race: 6 entries: White, n = 158; Hispanic, n = 46; Black, n = 33 and 3 others (1 missing)
  - PreinvasiveComponent: 2 entries: Absent, n = 192; Present, n = 57 (1 missing)
  - LVI: 2 entries: Absent, n = 163; Present, n = 86 (1 missing)
  - PNI: 2 entries: Absent, n = 174; Present, n = 75 (1 missing)
  - Death: 2 levels: FALSE (n = 81); TRUE (n = 168) and missing (n = 1)
  - Group: 2 entries: Treatment, n = 128; Control, n = 121 (1 missing)
  - Grade: 3 entries: 3, n = 101; 1, n = 80; 2, n = 68 (1 missing)
  - TStage: 4 entries: 4, n = 102; 3, n = 73; 2, n = 52 and 1 other (1 missing)
  - Anti-X-intensity: Mean = 2.41, SD = 0.62, range = [1, 3], 1 missing
  - Anti-Y-intensity: Mean = 1.97, SD = 0.77, range = [1, 3], 1 missing
  - LymphNodeMetastasis: 2 entries: Absent, n = 143; Present, n = 106 (1 missing)
  - Valid: 2 levels: FALSE (n = 139); TRUE (n = 110) and missing (n = 1)
  - Smoker: 2 levels: FALSE (n = 125); TRUE (n = 124) and missing (n = 1)
  - Grade_Level: 3 entries: high, n = 96; moderate, n = 79; low, n = 74 (1 missing)
  - DeathTime: 2 entries: Within1Year, n = 149; MoreThan1Year, n = 101
mydata %>% explore::describe_tbl()
250 observations with 21 variables
19 variables containing missings (NA)
0 variables with no variance

2.5 Ethics and IRB

2.5.1 Always Respect Patient Privacy

Always Respect Patient Privacy
- Health Information Privacy17
- Kişisel Verilerin Korunması18


2.6 Define Variable Types

Codes for defining variable types.19

2.6.1 Find Key Columns

print column names as vector

dput(names(mydata))
c("ID", "Name", "Sex", "Age", "Race", "PreinvasiveComponent", 
"LVI", "PNI", "LastFollowUpDate", "Death", "Group", "Grade", 
"TStage", "Anti-X-intensity", "Anti-Y-intensity", "LymphNodeMetastasis", 
"Valid", "Smoker", "Grade_Level", "SurgeryDate", "DeathTime")

2.6.1.1 Find ID and key columns to exclude from analysis

See the code as function in R/find_key.R.

keycolumns <- mydata %>% sapply(., FUN = dataMaid::isKey) %>% as_tibble() %>% select(which(.[1, 
    ] == TRUE)) %>% names()
keycolumns
[1] "ID"   "Name"

2.6.2 Variable Types

Get variable types

mydata %>% select(-keycolumns) %>% inspectdf::inspect_types()
# A tibble: 4 x 4
  type             cnt  pcnt col_name  
  <chr>          <int> <dbl> <list>    
1 character         11  57.9 <chr [11]>
2 logical            3  15.8 <chr [3]> 
3 numeric            3  15.8 <chr [3]> 
4 POSIXct POSIXt     2  10.5 <chr [2]> 
mydata %>% select(-keycolumns, -contains("Date")) %>% describer::describe() %>% knitr::kable(format = "markdown")
.column_name .column_class .column_type .count_elements .mean_value .sd_value .q0_value .q25_value .q50_value .q75_value .q100_value
Sex character character 250 NA NA Female NA NA NA Male
Age numeric double 250 49.048193 13.6814894 25 37 48 61 73
Race character character 250 NA NA Asian NA NA NA White
PreinvasiveComponent character character 250 NA NA Absent NA NA NA Present
LVI character character 250 NA NA Absent NA NA NA Present
PNI character character 250 NA NA Absent NA NA NA Present
Death logical logical 250 NA NA FALSE NA NA NA TRUE
Group character character 250 NA NA Control NA NA NA Treatment
Grade character character 250 NA NA 1 NA NA NA 3
TStage character character 250 NA NA 1 NA NA NA 4
Anti-X-intensity numeric double 250 2.405623 0.6222751 1 2 2 3 3
Anti-Y-intensity numeric double 250 1.967871 0.7718405 1 1 2 3 3
LymphNodeMetastasis character character 250 NA NA Absent NA NA NA Present
Valid logical logical 250 NA NA FALSE NA NA NA TRUE
Smoker logical logical 250 NA NA FALSE NA NA NA TRUE
Grade_Level character character 250 NA NA high NA NA NA moderate
DeathTime character character 250 NA NA MoreThan1Year NA NA NA Within1Year

Plot variable types

mydata %>% select(-keycolumns) %>% inspectdf::inspect_types() %>% inspectdf::show_plot()

# https://github.com/ropensci/visdat
# http://visdat.njtierney.com/articles/using_visdat.html
# https://cran.r-project.org/web/packages/visdat/index.html
# http://visdat.njtierney.com/

# visdat::vis_guess(mydata)

visdat::vis_dat(mydata)

mydata %>% explore::explore_tbl()

2.6.3 Define Variable Types

2.6.3.1 Find character variables

characterVariables <- mydata %>% select(-keycolumns) %>% inspectdf::inspect_types() %>% 
    dplyr::filter(type == "character") %>% dplyr::select(col_name) %>% pull() %>% 
    unlist()

characterVariables
 [1] "Sex"                  "Race"                 "PreinvasiveComponent"
 [4] "LVI"                  "PNI"                  "Group"               
 [7] "Grade"                "TStage"               "LymphNodeMetastasis" 
[10] "Grade_Level"          "DeathTime"           

2.6.3.2 Find categorical variables

categoricalVariables <- mydata %>% dplyr::select(-keycolumns, -contains("Date")) %>% 
    describer::describe() %>% janitor::clean_names() %>% dplyr::filter(column_type == 
    "factor") %>% dplyr::select(column_name) %>% dplyr::pull()

categoricalVariables
character(0)

2.6.3.3 Find continious variables

continiousVariables <- mydata %>% dplyr::select(-keycolumns, -contains("Date")) %>% 
    describer::describe() %>% janitor::clean_names() %>% dplyr::filter(column_type == 
    "numeric" | column_type == "double") %>% dplyr::select(column_name) %>% dplyr::pull()

continiousVariables
[1] "Age"              "Anti-X-intensity" "Anti-Y-intensity"

2.6.3.4 Find numeric variables

numericVariables <- mydata %>% select(-keycolumns) %>% inspectdf::inspect_types() %>% 
    dplyr::filter(type == "numeric") %>% dplyr::select(col_name) %>% pull() %>% unlist()

numericVariables
[1] "Age"              "Anti-X-intensity" "Anti-Y-intensity"

2.6.3.5 Find integer variables

integerVariables <- mydata %>% select(-keycolumns) %>% inspectdf::inspect_types() %>% 
    dplyr::filter(type == "integer") %>% dplyr::select(col_name) %>% pull() %>% unlist()

integerVariables
NULL

2.6.3.6 Find list variables

listVariables <- mydata %>% select(-keycolumns) %>% inspectdf::inspect_types() %>% 
    dplyr::filter(type == "list") %>% dplyr::select(col_name) %>% pull() %>% unlist()
listVariables
NULL

2.6.3.7 Find date variables

is_date <- function(x) inherits(x, c("POSIXct", "POSIXt"))

dateVariables <- names(which(sapply(mydata, FUN = is_date) == TRUE))
dateVariables
[1] "LastFollowUpDate" "SurgeryDate"     

2.7 Overview the Data

Codes for overviewing the data.20

2.7.1 View Data

View(mydata)
reactable::reactable(data = mydata, sortable = TRUE, resizable = TRUE, filterable = TRUE, 
    searchable = TRUE, pagination = TRUE, paginationType = "numbers", showPageSizeOptions = TRUE, 
    highlight = TRUE, striped = TRUE, outlined = TRUE, compact = TRUE, wrap = FALSE, 
    showSortIcon = TRUE, showSortable = TRUE)

2.7.2 Overview / Exploratory Data Analysis (EDA)

Summary of Data via summarytools 📦

summarytools::view(summarytools::dfSummary(mydata %>% select(-keycolumns)))
if (!dir.exists(here::here("out"))) {
    dir.create(here::here("out"))
}

summarytools::view(x = summarytools::dfSummary(mydata %>% select(-keycolumns)), file = here::here("out", 
    "mydata_summary.html"))

Summary via dataMaid 📦

if (!dir.exists(here::here("out"))) {
    dir.create(here::here("out"))
}

dataMaid::makeDataReport(data = mydata, file = here::here("out", "dataMaid_mydata.Rmd"), 
    replace = TRUE, openResult = FALSE, render = FALSE, quiet = TRUE)

Summary via explore 📦

if (!dir.exists(here::here("out"))) {
    dir.create(here::here("out"))
}

mydata %>% select(-dateVariables) %>% explore::report(output_file = "mydata_report.html", 
    output_dir = here::here("out"))

Glimpse of Data

glimpse(mydata %>% select(-keycolumns, -dateVariables))
Observations: 250
Variables: 17
$ Sex                  <chr> "Male", "Female", "Female", "Male", "Male", "Mal…
$ Age                  <dbl> 29, 47, 56, 67, 68, 69, 69, 63, 54, 41, 48, 31, …
$ Race                 <chr> "White", "White", "White", "White", "White", "Hi…
$ PreinvasiveComponent <chr> "Absent", "Absent", "Absent", "Present", "Absent…
$ LVI                  <chr> "Present", "Absent", "Absent", "Present", "Prese…
$ PNI                  <chr> "Present", "Absent", "Absent", "Absent", "Absent…
$ Death                <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE…
$ Group                <chr> "Treatment", "Treatment", "Treatment", "Treatmen…
$ Grade                <chr> "2", "1", "3", "1", "3", "2", "2", "3", "2", "3"…
$ TStage               <chr> "4", "2", "1", "4", "4", "4", "1", "3", "4", "1"…
$ `Anti-X-intensity`   <dbl> 3, 2, 3, 2, 3, 3, 2, 2, 2, 3, 3, 3, 1, 2, 3, 3, …
$ `Anti-Y-intensity`   <dbl> 3, 3, 1, 3, 2, 2, NA, 1, 1, 1, 2, 1, 2, 3, 3, 2,…
$ LymphNodeMetastasis  <chr> "Present", "Present", "Present", "Present", "Pre…
$ Valid                <lgl> TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, F…
$ Smoker               <lgl> TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, FALS…
$ Grade_Level          <chr> "moderate", "high", "low", "moderate", "high", "…
$ DeathTime            <chr> "Within1Year", "Within1Year", "Within1Year", "Wi…
mydata %>% explore::describe()
               variable type na na_pct unique min  mean max
1                    ID  chr  0    0.0    250  NA    NA  NA
2                  Name  chr  1    0.4    250  NA    NA  NA
3                   Sex  chr  1    0.4      3  NA    NA  NA
4                   Age  dbl  1    0.4     50  25 49.05  73
5                  Race  chr  1    0.4      7  NA    NA  NA
6  PreinvasiveComponent  chr  1    0.4      3  NA    NA  NA
7                   LVI  chr  1    0.4      3  NA    NA  NA
8                   PNI  chr  1    0.4      3  NA    NA  NA
9      LastFollowUpDate  dat  1    0.4     13  NA    NA  NA
10                Death  lgl  1    0.4      3   0  0.67   1
11                Group  chr  1    0.4      3  NA    NA  NA
12                Grade  chr  1    0.4      4  NA    NA  NA
13               TStage  chr  1    0.4      5  NA    NA  NA
14     Anti-X-intensity  dbl  1    0.4      4   1  2.41   3
15     Anti-Y-intensity  dbl  1    0.4      4   1  1.97   3
16  LymphNodeMetastasis  chr  1    0.4      3  NA    NA  NA
17                Valid  lgl  1    0.4      3   0  0.44   1
18               Smoker  lgl  1    0.4      3   0  0.50   1
19          Grade_Level  chr  1    0.4      4  NA    NA  NA
20          SurgeryDate  dat  1    0.4    231  NA    NA  NA
21            DeathTime  chr  0    0.0      2  NA    NA  NA

Explore

explore::explore(mydata)

2.7.3 Control Data

Control Data if matching expectations

visdat::vis_expect(data = mydata, expectation = ~.x == -1, show_perc = TRUE)

visdat::vis_expect(mydata, ~.x >= 25)

See missing values

visdat::vis_miss(airquality, cluster = TRUE)

visdat::vis_miss(airquality, sort_miss = TRUE)

xray::anomalies(mydata)
$variables
               Variable   q qNA  pNA qZero pZero qBlank pBlank qInf pInf
1                 Valid 250   1 0.4%   139 55.6%      0      -    0    -
2                Smoker 250   1 0.4%   125   50%      0      -    0    -
3                 Death 250   1 0.4%    81 32.4%      0      -    0    -
4                   Sex 250   1 0.4%     0     -      0      -    0    -
5  PreinvasiveComponent 250   1 0.4%     0     -      0      -    0    -
6                   LVI 250   1 0.4%     0     -      0      -    0    -
7                   PNI 250   1 0.4%     0     -      0      -    0    -
8                 Group 250   1 0.4%     0     -      0      -    0    -
9   LymphNodeMetastasis 250   1 0.4%     0     -      0      -    0    -
10                Grade 250   1 0.4%     0     -      0      -    0    -
11     Anti-X-intensity 250   1 0.4%     0     -      0      -    0    -
12     Anti-Y-intensity 250   1 0.4%     0     -      0      -    0    -
13          Grade_Level 250   1 0.4%     0     -      0      -    0    -
14               TStage 250   1 0.4%     0     -      0      -    0    -
15                 Race 250   1 0.4%     0     -      0      -    0    -
16     LastFollowUpDate 250   1 0.4%     0     -      0      -    0    -
17                  Age 250   1 0.4%     0     -      0      -    0    -
18          SurgeryDate 250   1 0.4%     0     -      0      -    0    -
19                 Name 250   1 0.4%     0     -      0      -    0    -
20            DeathTime 250   0    -     0     -      0      -    0    -
21                   ID 250   0    -     0     -      0      -    0    -
   qDistinct      type anomalous_percent
1          3   Logical               56%
2          3   Logical             50.4%
3          3   Logical             32.8%
4          3 Character              0.4%
5          3 Character              0.4%
6          3 Character              0.4%
7          3 Character              0.4%
8          3 Character              0.4%
9          3 Character              0.4%
10         4 Character              0.4%
11         4   Numeric              0.4%
12         4   Numeric              0.4%
13         4 Character              0.4%
14         5 Character              0.4%
15         7 Character              0.4%
16        13 Timestamp              0.4%
17        50   Numeric              0.4%
18       231 Timestamp              0.4%
19       250 Character              0.4%
20         2 Character                 -
21       250 Character                 -

$problem_variables
 [1] Variable          q                 qNA               pNA              
 [5] qZero             pZero             qBlank            pBlank           
 [9] qInf              pInf              qDistinct         type             
[13] anomalous_percent problems         
<0 rows> (or 0-length row.names)
xray::distributions(mydata)
================================================================================

[1] "Ignoring variable LastFollowUpDate: Unsupported type for visualization."

[1] "Ignoring variable SurgeryDate: Unsupported type for visualization."

          Variable p_1 p_10 p_25 p_50 p_75 p_90 p_99
1 Anti-X-intensity   1    2    2    2    3    3    3
2 Anti-Y-intensity   1    1    1    2    3    3    3
3              Age  26   31   37   48   61   68   73

2.7.4 Explore Data

Summary of Data via DataExplorer 📦

DataExplorer::plot_str(mydata)
DataExplorer::plot_str(mydata, type = "r")
DataExplorer::introduce(mydata)
# A tibble: 1 x 9
   rows columns discrete_columns continuous_colu… all_missing_col…
  <int>   <int>            <int>            <int>            <int>
1   250      21               18                3                0
# … with 4 more variables: total_missing_values <int>, complete_rows <int>,
#   total_observations <int>, memory_usage <dbl>
DataExplorer::plot_intro(mydata)

DataExplorer::plot_missing(mydata)

Drop columns

mydata2 <- DataExplorer::drop_columns(mydata, "TStage")
DataExplorer::plot_bar(mydata)

DataExplorer::plot_bar(mydata, with = "Death")

DataExplorer::plot_histogram(mydata)



3 Statistical Analysis

Learn these tests as highlighted in (Schmidt et al. 2017).21


4 Results

Write results as described in (Knijn, Simmer, and Nagtegaal 2015)22

  • Describe the number of patients included in the analysis and reason for dropout

  • Report patient/disease characteristics (including the biomarker of interest) with the number of missing values

  • Describe the interaction of the biomarker of interest with established prognostic variables

  • Include at least 90 % of initial cases included in univariate and multivariate analyses

  • Report the estimated effect (relative risk/odds ratio, confidence interval, and p value) in univariate analysis

  • Report the estimated effect (hazard rate/odds ratio, confidence interval, and p value) in multivariate analysis

  • Report the estimated effects (hazard ratio/odds ratio, confidence interval, and p value) of other prognostic factors included in multivariate analysis


4.1 Descriptive Statistics

Codes for Descriptive Statistics.23

4.1.1 Table One

Report Data properties via report 📦

mydata %>% dplyr::select(-dplyr::contains("Date")) %>% report::report()
The data contains 250 observations of the following variables:
  - ID: 250 entries: 001, n = 1; 002, n = 1; 003, n = 1 and 247 others
  - Name: 249 entries: Adayah, n = 1; Adeja, n = 1; Adelaina, n = 1 and 246 others (1 missing)
  - Sex: 2 entries: Male, n = 135; Female, n = 114 (1 missing)
  - Age: Mean = 49.05, SD = 13.68, range = [25, 73], 1 missing
  - Race: 6 entries: White, n = 158; Hispanic, n = 46; Black, n = 33 and 3 others (1 missing)
  - PreinvasiveComponent: 2 entries: Absent, n = 192; Present, n = 57 (1 missing)
  - LVI: 2 entries: Absent, n = 163; Present, n = 86 (1 missing)
  - PNI: 2 entries: Absent, n = 174; Present, n = 75 (1 missing)
  - Death: 2 levels: FALSE (n = 81); TRUE (n = 168) and missing (n = 1)
  - Group: 2 entries: Treatment, n = 128; Control, n = 121 (1 missing)
  - Grade: 3 entries: 3, n = 101; 1, n = 80; 2, n = 68 (1 missing)
  - TStage: 4 entries: 4, n = 102; 3, n = 73; 2, n = 52 and 1 other (1 missing)
  - Anti-X-intensity: Mean = 2.41, SD = 0.62, range = [1, 3], 1 missing
  - Anti-Y-intensity: Mean = 1.97, SD = 0.77, range = [1, 3], 1 missing
  - LymphNodeMetastasis: 2 entries: Absent, n = 143; Present, n = 106 (1 missing)
  - Valid: 2 levels: FALSE (n = 139); TRUE (n = 110) and missing (n = 1)
  - Smoker: 2 levels: FALSE (n = 125); TRUE (n = 124) and missing (n = 1)
  - Grade_Level: 3 entries: high, n = 96; moderate, n = 79; low, n = 74 (1 missing)
  - DeathTime: 2 entries: Within1Year, n = 149; MoreThan1Year, n = 101

Table 1 via arsenal 📦

# cat(names(mydata), sep = ' + \n')
library(arsenal)
tab1 <- arsenal::tableby(~Sex + Age + Race + PreinvasiveComponent + LVI + PNI + Death + 
    Group + Grade + TStage + `Anti-X-intensity` + `Anti-Y-intensity` + LymphNodeMetastasis + 
    Valid + Smoker + Grade_Level, data = mydata)
summary(tab1)
Overall (N=250)
Sex
   N-Miss 1
   Female 114 (45.8%)
   Male 135 (54.2%)
Age
   N-Miss 1
   Mean (SD) 49.048 (13.681)
   Range 25.000 - 73.000
Race
   N-Miss 1
   Asian 7 (2.8%)
   Bi-Racial 4 (1.6%)
   Black 33 (13.3%)
   Hispanic 46 (18.5%)
   Other 1 (0.4%)
   White 158 (63.5%)
PreinvasiveComponent
   N-Miss 1
   Absent 192 (77.1%)
   Present 57 (22.9%)
LVI
   N-Miss 1
   Absent 163 (65.5%)
   Present 86 (34.5%)
PNI
   N-Miss 1
   Absent 174 (69.9%)
   Present 75 (30.1%)
Death
   N-Miss 1
   FALSE 81 (32.5%)
   TRUE 168 (67.5%)
Group
   N-Miss 1
   Control 121 (48.6%)
   Treatment 128 (51.4%)
Grade
   N-Miss 1
   1 80 (32.1%)
   2 68 (27.3%)
   3 101 (40.6%)
TStage
   N-Miss 1
   1 22 (8.8%)
   2 52 (20.9%)
   3 73 (29.3%)
   4 102 (41.0%)
Anti-X-intensity
   N-Miss 1
   Mean (SD) 2.406 (0.622)
   Range 1.000 - 3.000
Anti-Y-intensity
   N-Miss 1
   Mean (SD) 1.968 (0.772)
   Range 1.000 - 3.000
LymphNodeMetastasis
   N-Miss 1
   Absent 143 (57.4%)
   Present 106 (42.6%)
Valid
   N-Miss 1
   FALSE 139 (55.8%)
   TRUE 110 (44.2%)
Smoker
   N-Miss 1
   FALSE 125 (50.2%)
   TRUE 124 (49.8%)
Grade_Level
   N-Miss 1
   high 96 (38.6%)
   low 74 (29.7%)
   moderate 79 (31.7%)

Table 1 via tableone 📦

library(tableone)
mydata %>% select(-keycolumns, -dateVariables) %>% tableone::CreateTableOne(data = .)
                                    
                                     Overall      
  n                                    250        
  Sex = Male (%)                       135 (54.2) 
  Age (mean (SD))                    49.05 (13.68)
  Race (%)                                        
     Asian                               7 ( 2.8) 
     Bi-Racial                           4 ( 1.6) 
     Black                              33 (13.3) 
     Hispanic                           46 (18.5) 
     Other                               1 ( 0.4) 
     White                             158 (63.5) 
  PreinvasiveComponent = Present (%)    57 (22.9) 
  LVI = Present (%)                     86 (34.5) 
  PNI = Present (%)                     75 (30.1) 
  Death = TRUE (%)                     168 (67.5) 
  Group = Treatment (%)                128 (51.4) 
  Grade (%)                                       
     1                                  80 (32.1) 
     2                                  68 (27.3) 
     3                                 101 (40.6) 
  TStage (%)                                      
     1                                  22 ( 8.8) 
     2                                  52 (20.9) 
     3                                  73 (29.3) 
     4                                 102 (41.0) 
  Anti-X-intensity (mean (SD))        2.41 (0.62) 
  Anti-Y-intensity (mean (SD))        1.97 (0.77) 
  LymphNodeMetastasis = Present (%)    106 (42.6) 
  Valid = TRUE (%)                     110 (44.2) 
  Smoker = TRUE (%)                    124 (49.8) 
  Grade_Level (%)                                 
     high                               96 (38.6) 
     low                                74 (29.7) 
     moderate                           79 (31.7) 
  DeathTime = Within1Year (%)          149 (59.6) 

Descriptive Statistics of Continuous Variables

mydata %>% select(continiousVariables, numericVariables, integerVariables) %>% summarytools::descr(., 
    style = "rmarkdown")
print(summarytools::descr(mydata), method = "render", table.classes = "st-small")
mydata %>% summarytools::descr(., stats = "common", transpose = TRUE, headings = FALSE)
mydata %>% summarytools::descr(stats = "common") %>% summarytools::tb()
mydata$Sex %>% summarytools::freq(cumul = FALSE, report.nas = FALSE) %>% summarytools::tb()
mydata %>% explore::describe() %>% dplyr::filter(unique < 5)
               variable type na na_pct unique min mean max
1                   Sex  chr  1    0.4      3  NA   NA  NA
2  PreinvasiveComponent  chr  1    0.4      3  NA   NA  NA
3                   LVI  chr  1    0.4      3  NA   NA  NA
4                   PNI  chr  1    0.4      3  NA   NA  NA
5                 Death  lgl  1    0.4      3   0 0.67   1
6                 Group  chr  1    0.4      3  NA   NA  NA
7                 Grade  chr  1    0.4      4  NA   NA  NA
8      Anti-X-intensity  dbl  1    0.4      4   1 2.41   3
9      Anti-Y-intensity  dbl  1    0.4      4   1 1.97   3
10  LymphNodeMetastasis  chr  1    0.4      3  NA   NA  NA
11                Valid  lgl  1    0.4      3   0 0.44   1
12               Smoker  lgl  1    0.4      3   0 0.50   1
13          Grade_Level  chr  1    0.4      4  NA   NA  NA
14            DeathTime  chr  0    0.0      2  NA   NA  NA
mydata %>% explore::describe() %>% dplyr::filter(na > 0)
               variable type na na_pct unique min  mean max
1                  Name  chr  1    0.4    250  NA    NA  NA
2                   Sex  chr  1    0.4      3  NA    NA  NA
3                   Age  dbl  1    0.4     50  25 49.05  73
4                  Race  chr  1    0.4      7  NA    NA  NA
5  PreinvasiveComponent  chr  1    0.4      3  NA    NA  NA
6                   LVI  chr  1    0.4      3  NA    NA  NA
7                   PNI  chr  1    0.4      3  NA    NA  NA
8      LastFollowUpDate  dat  1    0.4     13  NA    NA  NA
9                 Death  lgl  1    0.4      3   0  0.67   1
10                Group  chr  1    0.4      3  NA    NA  NA
11                Grade  chr  1    0.4      4  NA    NA  NA
12               TStage  chr  1    0.4      5  NA    NA  NA
13     Anti-X-intensity  dbl  1    0.4      4   1  2.41   3
14     Anti-Y-intensity  dbl  1    0.4      4   1  1.97   3
15  LymphNodeMetastasis  chr  1    0.4      3  NA    NA  NA
16                Valid  lgl  1    0.4      3   0  0.44   1
17               Smoker  lgl  1    0.4      3   0  0.50   1
18          Grade_Level  chr  1    0.4      4  NA    NA  NA
19          SurgeryDate  dat  1    0.4    231  NA    NA  NA
mydata %>% explore::describe()
               variable type na na_pct unique min  mean max
1                    ID  chr  0    0.0    250  NA    NA  NA
2                  Name  chr  1    0.4    250  NA    NA  NA
3                   Sex  chr  1    0.4      3  NA    NA  NA
4                   Age  dbl  1    0.4     50  25 49.05  73
5                  Race  chr  1    0.4      7  NA    NA  NA
6  PreinvasiveComponent  chr  1    0.4      3  NA    NA  NA
7                   LVI  chr  1    0.4      3  NA    NA  NA
8                   PNI  chr  1    0.4      3  NA    NA  NA
9      LastFollowUpDate  dat  1    0.4     13  NA    NA  NA
10                Death  lgl  1    0.4      3   0  0.67   1
11                Group  chr  1    0.4      3  NA    NA  NA
12                Grade  chr  1    0.4      4  NA    NA  NA
13               TStage  chr  1    0.4      5  NA    NA  NA
14     Anti-X-intensity  dbl  1    0.4      4   1  2.41   3
15     Anti-Y-intensity  dbl  1    0.4      4   1  1.97   3
16  LymphNodeMetastasis  chr  1    0.4      3  NA    NA  NA
17                Valid  lgl  1    0.4      3   0  0.44   1
18               Smoker  lgl  1    0.4      3   0  0.50   1
19          Grade_Level  chr  1    0.4      4  NA    NA  NA
20          SurgeryDate  dat  1    0.4    231  NA    NA  NA
21            DeathTime  chr  0    0.0      2  NA    NA  NA

4.1.2 Categorical Variables

Use R/gc_desc_cat.R to generate gc_desc_cat.Rmd containing descriptive statistics for categorical variables

source(here::here("R", "gc_desc_cat.R"))

4.1.2.1 Descriptive Statistics Sex

mydata %>% janitor::tabyl(Sex) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
Sex n percent valid_percent
Female 114 45.6% 45.8%
Male 135 54.0% 54.2%
NA 1 0.4% -

4.1.2.2 Descriptive Statistics Race

mydata %>% janitor::tabyl(Race) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
Race n percent valid_percent
Asian 7 2.8% 2.8%
Bi-Racial 4 1.6% 1.6%
Black 33 13.2% 13.3%
Hispanic 46 18.4% 18.5%
Other 1 0.4% 0.4%
White 158 63.2% 63.5%
NA 1 0.4% -

4.1.2.3 Descriptive Statistics PreinvasiveComponent

mydata %>% janitor::tabyl(PreinvasiveComponent) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
PreinvasiveComponent n percent valid_percent
Absent 192 76.8% 77.1%
Present 57 22.8% 22.9%
NA 1 0.4% -

4.1.2.4 Descriptive Statistics LVI

mydata %>% janitor::tabyl(LVI) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
LVI n percent valid_percent
Absent 163 65.2% 65.5%
Present 86 34.4% 34.5%
NA 1 0.4% -

4.1.2.5 Descriptive Statistics PNI

mydata %>% janitor::tabyl(PNI) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
PNI n percent valid_percent
Absent 174 69.6% 69.9%
Present 75 30.0% 30.1%
NA 1 0.4% -

4.1.2.6 Descriptive Statistics Group

mydata %>% janitor::tabyl(Group) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
Group n percent valid_percent
Control 121 48.4% 48.6%
Treatment 128 51.2% 51.4%
NA 1 0.4% -

4.1.2.7 Descriptive Statistics Grade

mydata %>% janitor::tabyl(Grade) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
Grade n percent valid_percent
1 80 32.0% 32.1%
2 68 27.2% 27.3%
3 101 40.4% 40.6%
NA 1 0.4% -

4.1.2.8 Descriptive Statistics TStage

mydata %>% janitor::tabyl(TStage) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
TStage n percent valid_percent
1 22 8.8% 8.8%
2 52 20.8% 20.9%
3 73 29.2% 29.3%
4 102 40.8% 41.0%
NA 1 0.4% -

4.1.2.9 Descriptive Statistics LymphNodeMetastasis

mydata %>% janitor::tabyl(LymphNodeMetastasis) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
LymphNodeMetastasis n percent valid_percent
Absent 143 57.2% 57.4%
Present 106 42.4% 42.6%
NA 1 0.4% -

4.1.2.10 Descriptive Statistics Grade_Level

mydata %>% janitor::tabyl(Grade_Level) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
Grade_Level n percent valid_percent
high 96 38.4% 38.6%
low 74 29.6% 29.7%
moderate 79 31.6% 31.7%
NA 1 0.4% -

4.1.2.11 Descriptive Statistics DeathTime

mydata %>% janitor::tabyl(DeathTime) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
DeathTime n percent
MoreThan1Year 101 40.4%
Within1Year 149 59.6%
race_stats <- summarytools::freq(mydata$Race)
print(race_stats, report.nas = FALSE, totals = FALSE, display.type = FALSE, Variable.label = "Race Group")
mydata %>% explore::describe(PreinvasiveComponent)
variable = PreinvasiveComponent
type     = character
na       = 1 of 250 (0.4%)
unique   = 3
 Absent  = 192 (76.8%)
 Present = 57 (22.8%)
 NA      = 1 (0.4%)
## Frequency or custom tables for categorical variables
SmartEDA::ExpCTable(mydata, Target = NULL, margin = 1, clim = 10, nlim = 5, round = 2, 
    bin = NULL, per = T)
               Variable         Valid Frequency Percent CumPercent
1                   Sex        Female       114    45.6       45.6
2                   Sex          Male       135    54.0       99.6
3                   Sex            NA         1     0.4      100.0
4                   Sex         TOTAL       250      NA         NA
5                  Race         Asian         7     2.8        2.8
6                  Race     Bi-Racial         4     1.6        4.4
7                  Race         Black        33    13.2       17.6
8                  Race      Hispanic        46    18.4       36.0
9                  Race            NA         1     0.4       36.4
10                 Race         Other         1     0.4       36.8
11                 Race         White       158    63.2      100.0
12                 Race         TOTAL       250      NA         NA
13 PreinvasiveComponent        Absent       192    76.8       76.8
14 PreinvasiveComponent            NA         1     0.4       77.2
15 PreinvasiveComponent       Present        57    22.8      100.0
16 PreinvasiveComponent         TOTAL       250      NA         NA
17                  LVI        Absent       163    65.2       65.2
18                  LVI            NA         1     0.4       65.6
19                  LVI       Present        86    34.4      100.0
20                  LVI         TOTAL       250      NA         NA
21                  PNI        Absent       174    69.6       69.6
22                  PNI            NA         1     0.4       70.0
23                  PNI       Present        75    30.0      100.0
24                  PNI         TOTAL       250      NA         NA
25                Group       Control       121    48.4       48.4
26                Group            NA         1     0.4       48.8
27                Group     Treatment       128    51.2      100.0
28                Group         TOTAL       250      NA         NA
29                Grade             1        80    32.0       32.0
30                Grade             2        68    27.2       59.2
31                Grade             3       101    40.4       99.6
32                Grade            NA         1     0.4      100.0
33                Grade         TOTAL       250      NA         NA
34               TStage             1        22     8.8        8.8
35               TStage             2        52    20.8       29.6
36               TStage             3        73    29.2       58.8
37               TStage             4       102    40.8       99.6
38               TStage            NA         1     0.4      100.0
39               TStage         TOTAL       250      NA         NA
40  LymphNodeMetastasis        Absent       143    57.2       57.2
41  LymphNodeMetastasis            NA         1     0.4       57.6
42  LymphNodeMetastasis       Present       106    42.4      100.0
43  LymphNodeMetastasis         TOTAL       250      NA         NA
44          Grade_Level          high        96    38.4       38.4
45          Grade_Level           low        74    29.6       68.0
46          Grade_Level      moderate        79    31.6       99.6
47          Grade_Level            NA         1     0.4      100.0
48          Grade_Level         TOTAL       250      NA         NA
49            DeathTime MoreThan1Year       101    40.4       40.4
50            DeathTime   Within1Year       149    59.6      100.0
51            DeathTime         TOTAL       250      NA         NA
52     Anti-X-intensity             1        18     7.2        7.2
53     Anti-X-intensity             2       112    44.8       52.0
54     Anti-X-intensity             3       119    47.6       99.6
55     Anti-X-intensity            NA         1     0.4      100.0
56     Anti-X-intensity         TOTAL       250      NA         NA
57     Anti-Y-intensity             1        78    31.2       31.2
58     Anti-Y-intensity             2       101    40.4       71.6
59     Anti-Y-intensity             3        70    28.0       99.6
60     Anti-Y-intensity            NA         1     0.4      100.0
61     Anti-Y-intensity         TOTAL       250      NA         NA
inspectdf::inspect_cat(mydata)
# A tibble: 16 x 5
   col_name               cnt common      common_pcnt levels            
   <chr>                <int> <chr>             <dbl> <named list>      
 1 Death                    3 TRUE               67.2 <tibble [3 × 3]>  
 2 DeathTime                2 Within1Year        59.6 <tibble [2 × 3]>  
 3 Grade                    4 3                  40.4 <tibble [4 × 3]>  
 4 Grade_Level              4 high               38.4 <tibble [4 × 3]>  
 5 Group                    3 Treatment          51.2 <tibble [3 × 3]>  
 6 ID                     250 001                 0.4 <tibble [250 × 3]>
 7 LVI                      3 Absent             65.2 <tibble [3 × 3]>  
 8 LymphNodeMetastasis      3 Absent             57.2 <tibble [3 × 3]>  
 9 Name                   250 Adayah              0.4 <tibble [250 × 3]>
10 PNI                      3 Absent             69.6 <tibble [3 × 3]>  
11 PreinvasiveComponent     3 Absent             76.8 <tibble [3 × 3]>  
12 Race                     7 White              63.2 <tibble [7 × 3]>  
13 Sex                      3 Male               54   <tibble [3 × 3]>  
14 Smoker                   3 FALSE              50   <tibble [3 × 3]>  
15 TStage                   5 4                  40.8 <tibble [5 × 3]>  
16 Valid                    3 FALSE              55.6 <tibble [3 × 3]>  
inspectdf::inspect_cat(mydata)$levels$Group
# A tibble: 3 x 3
  value      prop   cnt
  <chr>     <dbl> <int>
1 Treatment 0.512   128
2 Control   0.484   121
3 <NA>      0.004     1

4.1.2.12 Split-Group Stats Categorical

library(summarytools)

grouped_freqs <- stby(data = mydata$Smoker, INDICES = mydata$Sex, FUN = freq, cumul = FALSE, 
    report.nas = FALSE)

grouped_freqs %>% tb(order = 2)

4.1.2.13 Grouped Categorical

summarytools::stby(list(x = mydata$LVI, y = mydata$LymphNodeMetastasis), mydata$PNI, 
    summarytools::ctable)
with(mydata, summarytools::stby(list(x = LVI, y = LymphNodeMetastasis), PNI, summarytools::ctable))
SmartEDA::ExpCTable(mydata, Target = "Sex", margin = 1, clim = 10, nlim = NULL, round = 2, 
    bin = 4, per = F)
               VARIABLE      CATEGORY Sex:Female Sex:Male Sex:NA TOTAL
1                  Race         Asian          3        3      1     7
2                  Race     Bi-Racial          2        2      0     4
3                  Race         Black          9       24      0    33
4                  Race      Hispanic         24       22      0    46
5                  Race            NA          0        1      0     1
6                  Race         Other          0        1      0     1
7                  Race         White         76       82      0   158
8                  Race         TOTAL        114      135      1   250
9  PreinvasiveComponent        Absent         86      106      0   192
10 PreinvasiveComponent            NA          0        0      1     1
11 PreinvasiveComponent       Present         28       29      0    57
12 PreinvasiveComponent         TOTAL        114      135      1   250
13                  LVI        Absent         75       87      1   163
14                  LVI            NA          0        1      0     1
15                  LVI       Present         39       47      0    86
16                  LVI         TOTAL        114      135      1   250
17                  PNI        Absent         77       97      0   174
18                  PNI            NA          1        0      0     1
19                  PNI       Present         36       38      1    75
20                  PNI         TOTAL        114      135      1   250
21                Group       Control         60       61      0   121
22                Group            NA          1        0      0     1
23                Group     Treatment         53       74      1   128
24                Group         TOTAL        114      135      1   250
25                Grade             1         38       42      0    80
26                Grade             2         37       30      1    68
27                Grade             3         38       63      0   101
28                Grade            NA          1        0      0     1
29                Grade         TOTAL        114      135      1   250
30               TStage             1         12       10      0    22
31               TStage             2         23       29      0    52
32               TStage             3         34       39      0    73
33               TStage             4         44       57      1   102
34               TStage            NA          1        0      0     1
35               TStage         TOTAL        114      135      1   250
36  LymphNodeMetastasis        Absent         68       74      1   143
37  LymphNodeMetastasis            NA          1        0      0     1
38  LymphNodeMetastasis       Present         45       61      0   106
39  LymphNodeMetastasis         TOTAL        114      135      1   250
40          Grade_Level          high         36       60      0    96
41          Grade_Level           low         39       35      0    74
42          Grade_Level      moderate         39       39      1    79
43          Grade_Level            NA          0        1      0     1
44          Grade_Level         TOTAL        114      135      1   250
45            DeathTime MoreThan1Year         51       50      0   101
46            DeathTime   Within1Year         63       85      1   149
47            DeathTime         TOTAL        114      135      1   250
48     Anti-X-intensity             1          8       10      0    18
49     Anti-X-intensity             2         50       62      0   112
50     Anti-X-intensity             3         56       62      1   119
51     Anti-X-intensity            NA          0        1      0     1
52     Anti-X-intensity         TOTAL        114      135      1   250
53     Anti-Y-intensity             1         38       39      1    78
54     Anti-Y-intensity             2         51       50      0   101
55     Anti-Y-intensity             3         25       45      0    70
56     Anti-Y-intensity            NA          0        1      0     1
57     Anti-Y-intensity         TOTAL        114      135      1   250
mydata %>% select(characterVariables) %>% select(PreinvasiveComponent, PNI, LVI) %>% 
    reactable::reactable(data = ., groupBy = c("PreinvasiveComponent", "PNI"), columns = list(LVI = reactable::colDef(aggregate = "count")))

4.1.3 Continious Variables

questionr:::icut()
source(here::here("R", "gc_desc_cont.R"))

Descriptive Statistics Age

mydata %>% jmv::descriptives(data = ., vars = "Age", hist = TRUE, dens = TRUE, box = TRUE, 
    violin = TRUE, dot = TRUE, mode = TRUE, sd = TRUE, variance = TRUE, skew = TRUE, 
    kurt = TRUE, quart = TRUE)

 DESCRIPTIVES

 Descriptives                      
 ───────────────────────────────── 
                          Age      
 ───────────────────────────────── 
   N                         249   
   Missing                     1   
   Mean                     49.0   
   Median                   48.0   
   Mode                     43.0   
   Standard deviation       13.7   
   Variance                  187   
   Minimum                  25.0   
   Maximum                  73.0   
   Skewness               0.0330   
   Std. error skewness     0.154   
   Kurtosis                -1.20   
   Std. error kurtosis     0.307   
   25th percentile          37.0   
   50th percentile          48.0   
   75th percentile          61.0   
 ───────────────────────────────── 

Descriptive Statistics Anti-X-intensity

mydata %>% jmv::descriptives(data = ., vars = "Anti-X-intensity", hist = TRUE, dens = TRUE, 
    box = TRUE, violin = TRUE, dot = TRUE, mode = TRUE, sd = TRUE, variance = TRUE, 
    skew = TRUE, kurt = TRUE, quart = TRUE)

 DESCRIPTIVES

 Descriptives                                
 ─────────────────────────────────────────── 
                          Anti-X-intensity   
 ─────────────────────────────────────────── 
   N                                   249   
   Missing                               1   
   Mean                               2.41   
   Median                             2.00   
   Mode                               3.00   
   Standard deviation                0.622   
   Variance                          0.387   
   Minimum                            1.00   
   Maximum                            3.00   
   Skewness                         -0.548   
   Std. error skewness               0.154   
   Kurtosis                         -0.608   
   Std. error kurtosis               0.307   
   25th percentile                    2.00   
   50th percentile                    2.00   
   75th percentile                    3.00   
 ─────────────────────────────────────────── 

Descriptive Statistics Anti-Y-intensity

mydata %>% jmv::descriptives(data = ., vars = "Anti-Y-intensity", hist = TRUE, dens = TRUE, 
    box = TRUE, violin = TRUE, dot = TRUE, mode = TRUE, sd = TRUE, variance = TRUE, 
    skew = TRUE, kurt = TRUE, quart = TRUE)

 DESCRIPTIVES

 Descriptives                                
 ─────────────────────────────────────────── 
                          Anti-Y-intensity   
 ─────────────────────────────────────────── 
   N                                   249   
   Missing                               1   
   Mean                               1.97   
   Median                             2.00   
   Mode                               2.00   
   Standard deviation                0.772   
   Variance                          0.596   
   Minimum                            1.00   
   Maximum                            3.00   
   Skewness                         0.0552   
   Std. error skewness               0.154   
   Kurtosis                          -1.32   
   Std. error kurtosis               0.307   
   25th percentile                    1.00   
   50th percentile                    2.00   
   75th percentile                    3.00   
 ─────────────────────────────────────────── 

tab <- tableone::CreateTableOne(data = mydata)
# ?print.ContTable
tab$ContTable
                              
                               Overall      
  n                            250          
  Age (mean (SD))              49.05 (13.68)
  Anti-X-intensity (mean (SD))  2.41 (0.62) 
  Anti-Y-intensity (mean (SD))  1.97 (0.77) 
print(tab$ContTable, nonnormal = c("Anti-X-intensity"))
                                 
                                  Overall           
  n                               250               
  Age (mean (SD))                 49.05 (13.68)     
  Anti-X-intensity (median [IQR])  2.00 [2.00, 3.00]
  Anti-Y-intensity (mean (SD))     1.97 (0.77)      
mydata %>% explore::describe(Age)
variable = Age
type     = double
na       = 1 of 250 (0.4%)
unique   = 50
min|max  = 25 | 73
q05|q95  = 28 | 70
q25|q75  = 37 | 61
median   = 48
mean     = 49.04819
mydata %>% select(continiousVariables) %>% SmartEDA::ExpNumStat(data = ., by = "A", 
    gp = NULL, Qnt = seq(0, 1, 0.1), MesofShape = 2, Outlier = TRUE, round = 2)
inspectdf::inspect_num(mydata, breaks = 10)
# A tibble: 3 x 10
  col_name        min    q1 median  mean    q3   max     sd pcnt_na hist        
  <chr>         <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl>  <dbl>   <dbl> <named list>
1 Age              25    37     48 49.0     61    73 13.7       0.4 <tibble [12…
2 Anti-X-inten…     1     2      2  2.41     3     3  0.622     0.4 <tibble [12…
3 Anti-Y-inten…     1     1      2  1.97     3     3  0.772     0.4 <tibble [12…
inspectdf::inspect_num(mydata)$hist$Age
# A tibble: 27 x 2
   value         prop
   <chr>        <dbl>
 1 [-Inf, 24) 0      
 2 [24, 26)   0.00803
 3 [26, 28)   0.0361 
 4 [28, 30)   0.0281 
 5 [30, 32)   0.0402 
 6 [32, 34)   0.0482 
 7 [34, 36)   0.0562 
 8 [36, 38)   0.0361 
 9 [38, 40)   0.0402 
10 [40, 42)   0.0482 
# … with 17 more rows
inspectdf::inspect_num(mydata, breaks = 10) %>% inspectdf::show_plot()

4.1.3.1 Split-Group Stats Continious

grouped_descr <- summarytools::stby(data = mydata, INDICES = mydata$Sex, FUN = summarytools::descr, 
    stats = "common")
# grouped_descr %>% summarytools::tb(order = 2)
grouped_descr %>% summarytools::tb()

4.1.3.2 Grouped Continious

summarytools::stby(data = mydata, INDICES = mydata$PreinvasiveComponent, FUN = summarytools::descr, 
    stats = c("mean", "sd", "min", "med", "max"), transpose = TRUE)
with(mydata, summarytools::stby(Age, PreinvasiveComponent, summarytools::descr), 
    stats = c("mean", "sd", "min", "med", "max"), transpose = TRUE)
mydata %>% group_by(PreinvasiveComponent) %>% summarytools::descr(stats = "fivenum")
## Summary statistics by – category
SmartEDA::ExpNumStat(mydata, by = "GA", gp = "PreinvasiveComponent", Qnt = seq(0, 
    1, 0.1), MesofShape = 2, Outlier = TRUE, round = 2)
  Vname                        Group  TN nNeg nZero nPos NegInf PosInf NA_Value
1   Age     PreinvasiveComponent:All 250    0     0  249      0      0        1
2   Age  PreinvasiveComponent:Absent 192    0     0  191      0      0        1
3   Age PreinvasiveComponent:Present  57    0     0   57      0      0        0
4   Age      PreinvasiveComponent:NA   0    0     0    0      0      0        0
  Per_of_Missing   sum min  max  mean median    SD   CV  IQR Skewness Kurtosis
1           0.40 12213  25   73 49.05     48 13.68 0.28 24.0     0.03    -1.20
2           0.52  9143  25   73 47.87     47 13.43 0.28 22.5     0.12    -1.12
3           0.00  3033  27   73 53.21     58 13.86 0.26 24.0    -0.33    -1.24
4            NaN     0 Inf -Inf   NaN     NA    NA   NA   NA      NaN      NaN
  0%  10% 20% 30% 40% 50% 60% 70% 80%  90% 100% LB.25% UB.75% nOutliers
1 25 31.0  35  40  43  48  54  59  64 68.0   73   1.00  97.00         0
2 25 30.0  34  39  43  47  52  57  62 67.0   73   3.75  93.75         0
3 27 32.6  37  45  49  58  60  63  66 69.4   73   5.00 101.00         0
4 NA   NA  NA  NA  NA  NA  NA  NA  NA   NA   NA     NA     NA         0

4.2 Survival Analysis

Codes for Survival Analysis24

  • Survival analysis with strata, clusters, frailties and competing risks in in Finalfit

https://www.datasurg.net/2019/09/12/survival-analysis-with-strata-clusters-frailties-and-competing-risks-in-in-finalfit/

  • Intracranial WHO grade I meningioma: a competing risk analysis of progression and disease-specific survival

https://link.springer.com/article/10.1007/s00701-019-04096-9

Calculate survival time

mydata$int <- lubridate::interval(lubridate::ymd(mydata$SurgeryDate), lubridate::ymd(mydata$LastFollowUpDate))
mydata$OverallTime <- lubridate::time_length(mydata$int, "month")
mydata$OverallTime <- round(mydata$OverallTime, digits = 1)

recode death status outcome as numbers for survival analysis

## Recoding mydata$Death into mydata$Outcome
mydata$Outcome <- forcats::fct_recode(as.character(mydata$Death), `1` = "TRUE", `0` = "FALSE")
mydata$Outcome <- as.numeric(as.character(mydata$Outcome))

it is always a good practice to double-check after recoding25

table(mydata$Death, mydata$Outcome)
       
          0   1
  FALSE  81   0
  TRUE    0 168

4.2.1 Kaplan-Meier

library(survival)
# data(lung) km <- with(lung, Surv(time, status))
km <- with(mydata, Surv(OverallTime, Outcome))
head(km, 80)
 [1]  3.4   7.7   6.3   6.6   9.4   9.1   6.5+ 10.5+  8.2   8.7  11.6  11.3 
[13]  4.8   6.7  11.6+  6.2+  7.2+  6.4   3.3   9.7  11.4+  8.0+  9.4  10.9+
[25]  5.1+  8.9   3.5   9.0   3.8+  5.8  10.2+  3.7   8.3+  7.3   3.1   5.9 
[37]  8.0+  7.4   9.5+  3.7+ 10.2   3.9   9.1+  6.6   7.3+  5.5   5.4   3.8 
[49]  8.8+  8.8   3.2   7.0  10.7   6.6   8.6   5.5  11.5   9.7    NA  10.5 
[61]  7.5   9.0   7.8  10.6   5.0   6.3   4.3   4.4+  7.5   6.3   8.5+  9.0+
[73]  7.1   6.0   5.8+  3.0   8.2   8.6   5.7   7.2+
plot(km)

Kaplan-Meier Plot Log-Rank Test

# Drawing Survival Curves Using ggplot2
# https://rpkgs.datanovia.com/survminer/reference/ggsurvplot.html
dependentKM <- "Surv(OverallTime, Outcome)"
explanatoryKM <- "LVI"

mydata %>%
  finalfit::surv_plot(.data = .,
                      dependent = dependentKM,
                      explanatory = explanatoryKM,
                      xlab='Time (months)',
                      pval=TRUE,
                      legend = 'none',
                      break.time.by = 12,
                      xlim = c(0,60)
                      # legend.labs = c('a','b')
                      )

# Drawing Survival Curves Using ggplot2
# https://rpkgs.datanovia.com/survminer/reference/ggsurvplot.html

mydata %>%
  finalfit::surv_plot(.data = .,
                      dependent = "Surv(OverallTime, Outcome)",
                      explanatory = "LVI",
                      xlab='Time (months)',
                      pval=TRUE,
                      legend = 'none',
                      break.time.by = 12,
                      xlim = c(0,60)
                      # legend.labs = c('a','b')
                      )

4.2.2 Univariate Cox-Regression

library(finalfit)
library(survival)
explanatoryUni <- "LVI"
dependentUni <- "Surv(OverallTime, Outcome)"

tUni <- mydata %>% finalfit::finalfit(dependentUni, explanatoryUni)

knitr::kable(tUni, row.names = FALSE, align = c("l", "l", "r", "r", "r", "r"))
Dependent: Surv(OverallTime, Outcome) all HR (univariable) HR (multivariable)
LVI Absent 163 (100.0) NA NA
Present 86 (100.0) 1.09 (0.77-1.54, p=0.613) 1.09 (0.77-1.54, p=0.613)
tUni_df <- tibble::as_tibble(tUni, .name_repair = "minimal") %>% janitor::clean_names()

tUni_df_descr <- paste0("When ", tUni_df$dependent_surv_overall_time_outcome[1], 
    " is ", tUni_df$x[2], ", there is ", tUni_df$hr_univariable[2], " times risk than ", 
    "when ", tUni_df$dependent_surv_overall_time_outcome[1], " is ", tUni_df$x[1], 
    ".")

When LVI is Present, there is 1.09 (0.77-1.54, p=0.613) times risk than when LVI is Absent.

4.2.3 Kaplan-Meier Median Survival

km_fit <- survfit(Surv(OverallTime, Outcome) ~ LVI, data = mydata)
km_fit
Call: survfit(formula = Surv(OverallTime, Outcome) ~ LVI, data = mydata)

   4 observations deleted due to missingness 
              n events median 0.95LCL 0.95UCL
LVI=Absent  161    119   17.6    13.6    23.5
LVI=Present  85     46   10.6     9.4    26.0
plot(km_fit)

# summary(km_fit)
km_fit_median_df <- summary(km_fit)
km_fit_median_df <- as.data.frame(km_fit_median_df$table) %>% janitor::clean_names() %>% 
    tibble::rownames_to_column()
km_fit_median_definition <- km_fit_median_df %>% dplyr::mutate(description = glue::glue("When {rowname}, median survival is {median} [{x0_95lcl} - {x0_95ucl}, 95% CI] months.")) %>% 
    dplyr::select(description) %>% pull()

When LVI=Absent, median survival is 17.6 [13.6 - 23.5, 95% CI] months., When LVI=Present, median survival is 10.6 [9.4 - 26, 95% CI] months.

4.2.4 1-3-5-yr survival

summary(km_fit, times = c(12, 36, 60))
Call: survfit(formula = Surv(OverallTime, Outcome) ~ LVI, data = mydata)

4 observations deleted due to missingness 
                LVI=Absent 
 time n.risk n.event survival std.err lower 95% CI upper 95% CI
   12     81      61    0.587  0.0409        0.513        0.673
   36     18      45    0.211  0.0378        0.148        0.300

                LVI=Present 
 time n.risk n.event survival std.err lower 95% CI upper 95% CI
   12     15      38    0.409  0.0671        0.297        0.564
   36      6       4    0.273  0.0721        0.163        0.458
km_fit_summary <- summary(km_fit, times = c(12, 36, 60))

km_fit_df <- as.data.frame(km_fit_summary[c("strata", "time", "n.risk", "n.event", 
    "surv", "std.err", "lower", "upper")])
km_fit_definition <- km_fit_df %>% dplyr::mutate(description = glue::glue("When {strata}, {time} month survival is {scales::percent(surv)} [{scales::percent(lower)}-{scales::percent(upper)}, 95% CI].")) %>% 
    dplyr::select(description) %>% pull()

When LVI=Absent, 12 month survival is 58.7% [51.3%-67%, 95% CI]., When LVI=Absent, 36 month survival is 21.1% [14.8%-30%, 95% CI]., When LVI=Present, 12 month survival is 40.9% [29.7%-56%, 95% CI]., When LVI=Present, 36 month survival is 27.3% [16.3%-46%, 95% CI].

4.2.5 Pairwise comparison

dependentKM <- "Surv(OverallTime, Outcome)"
explanatoryKM <- "TStage"

mydata %>%
  finalfit::surv_plot(.data = .,
                      dependent = dependentKM,
                      explanatory = explanatoryKM,
                      xlab='Time (months)',
                      pval=TRUE,
                      legend = 'none',
                      break.time.by = 12,
                      xlim = c(0,60)
                      # legend.labs = c('a','b')
                      )

4.2.6 Multivariate Analysis Survival



5 Discussion

  • Interpret the results in context of the working hypothesis elaborated in the introduction and other relevant studies; include a discussion of limitations of the study.

  • Discuss potential clinical applications and implications for future research

References

Knijn, N., F. Simmer, and I. D. Nagtegaal. 2015. “Recommendations for Reporting Histopathology Studies: A Proposal.” Virchows Archiv 466 (6): 611–15. https://doi.org/10.1007/s00428-015-1762-3.

Schmidt, Robert L., Deborah J. Chute, Jorie M. Colbert-Getz, Adolfo Firpo-Betancourt, Daniel S. James, Julie K. Karp, Douglas C. Miller, et al. 2017. “Statistical Literacy Among Academic Pathologists: A Survey Study to Gauge Knowledge of Frequently Used Statistical Tests Among Trainees and Faculty.” Archives of Pathology & Laboratory Medicine 141 (2): 279–87. https://doi.org/10.5858/arpa.2016-0200-OA.


  1. From Table 1: Proposed items for reporting histopathology studies. Recommendations for reporting histopathology studies: a proposal Virchows Arch (2015) 466:611–615 DOI 10.1007/s00428-015-1762-3↩︎

  2. From Table 1: Proposed items for reporting histopathology studies. Recommendations for reporting histopathology studies: a proposal Virchows Arch (2015) 466:611–615 DOI 10.1007/s00428-015-1762-3↩︎

  3. See childRmd/_01header.Rmd file for other general settings↩︎

  4. Change echo = FALSE to hide codes after knitting.↩︎

  5. See childRmd/_02fakeData.Rmd file for other codes↩︎

  6. Synthea The validity of synthetic clinical data: a validation study of a leading synthetic data generator (Synthea) using clinical quality measures. BMC Med Inform Decis Mak 19, 44 (2019) doi:10.1186/s12911-019-0793-0↩︎

  7. https://bmcmedinformdecismak.biomedcentral.com/articles/10.1186/s12911-019-0793-0↩︎

  8. Synthetic Patient Generation↩︎

  9. Basic Setup and Running↩︎

  10. intelligent patient data generator (iPDG)↩︎

  11. https://medium.com/free-code-camp/how-our-test-data-generator-makes-fake-data-look-real-ace01c5bde4a↩︎

  12. https://forums.librehealth.io/t/demo-data-generation/203↩︎

  13. https://mihin.org/services/patient-generator/↩︎

  14. lung, cancer, breast datası ile birleştir↩︎

  15. See childRmd/_03importData.Rmd file for other codes↩︎

  16. See childRmd/_04briefSummary.Rmd file for other codes↩︎

  17. https://www.hhs.gov/hipaa/index.html↩︎

  18. Kişisel verilerin kaydedilmesi ve kişisel verileri hukuka aykırı olarak verme veya ele geçirme Türk Ceza Kanunu’nun 135. ve 136. maddesi kapsamında bizim hukuk sistemimizde suç olarak tanımlanmıştır. Kişisel verilerin kaydedilmesi suçunun cezası 1 ila 3 yıl hapis cezasıdır. Suçun nitelikli hali ise, kamu görevlisi tarafından görevin verdiği yetkinin kötüye kullanılarak veya belirli bir meslek veya sanatın sağladığı kolaylıktan yararlanılarak işlenmesidir ki bu durumda suçun cezası 1.5 ile 4.5 yıl hapis cezası olacaktır.↩︎

  19. See childRmd/_06variableTypes.Rmd file for other codes↩︎

  20. See childRmd/_07overView.Rmd file for other codes↩︎

  21. Statistical Literacy Among Academic Pathologists: A Survey Study to Gauge Knowledge of Frequently Used Statistical Tests Among Trainees and Faculty. Archives of Pathology & Laboratory Medicine: February 2017, Vol. 141, No. 2, pp. 279-287. https://doi.org/10.5858/arpa.2016-0200-OA↩︎

  22. From Table 1: Proposed items for reporting histopathology studies. Recommendations for reporting histopathology studies: a proposal Virchows Arch (2015) 466:611–615 DOI 10.1007/s00428-015-1762-3↩︎

  23. See childRmd/_11descriptives.Rmd file for other codes↩︎

  24. See childRmd/_18survival.Rmd file for other codes, and childRmd/_19shinySurvival.Rmd for shiny application↩︎

  25. JAMA retraction after miscoding – new Finalfit function to check recoding↩︎

  26. See childRmd/_23footer.Rmd file for other codes↩︎

  27. Smith AM, Katz DS, Niemeyer KE, FORCE11 Software Citation Working Group. (2016) Software Citation Principles. PeerJ Computer Science 2:e86. DOI: 10.7717/peerj-cs.86 https://www.force11.org/software-citation-principles↩︎

 

A work by Serdar Balci

drserdarbalci@gmail.com